<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//前台控制器
class IndexController extends Controller{
	public function index(){
//		//1.获取顶级分类
//		$cateModel = new \Common\Model\Cate;
//		$topCate = $cateModel->where("pid=0")->orderBy('csort','ASC')->get();
////		p($topCate);
//		View::with('topCate',$topCate);
		//2.获取文章
		//select from article where is_recycle=0
		$arcModel=new \Common\Model\Arc;
		
		$data = $arcModel
			  ->join('category','category_cid','=','cid')

			  ->orderBy('sendtime','DESC')
			  ->get();

		//获取标签
		$arcTagModel=new \Common\Model\ArcTag;
		//标签是多个，所以要遍历标签列表下的内容
		foreach ($data as $k => $v) {
			//因为打印$data时没有tag，所以要压入tag
			$data[$k]['tag']=$arcTagModel
							->join('tag','tag_tid','=','tid')
							->where("article_aid={$v['aid']}")
							->get();
		}
//		p($data);
		View::with('data',$data);
		
				$arcModel=new \Common\Model\Arc;
		$arcData=$arcModel
				->orderBy('sendtime')
				->limit(2)
				->get();
//		p($arcData);
		View::with('arcData',$arcData);
		//链接
		$linkModel=new \Common\Model\Link;
		$linkData=$linkModel->get();
//		p($linkData);
		View::with('linkData',$linkData);
		

		View::make();
		
		
	}
	
 
}
